package cn.zyzpp.service.resume.impl;

import cn.zyzpp.dao.ExpectationDao;
import cn.zyzpp.entity.resume.Expectation;
import cn.zyzpp.service.resume.ExpectationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Create by yster@foxmail.com 2018/5/21/021 22:41
 */
@Service
@CacheConfig(cacheNames = {"ExpectationService"})
public class ExpectationServiceImpl implements ExpectationService {
    @Autowired
    private ExpectationDao expectationDao;

    @Override
    @CacheEvict(allEntries = true)
    public void save(Expectation expectation, int uid) {
        expectation.setUid(uid);
        expectationDao.save(expectation);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void delect(int id) {
        expectationDao.deleteAllById(id);
    }

    @Transactional
    @Override
    @CacheEvict(allEntries = true)
    public void updataByUid(Expectation expectation) {
        Expectation expectation1 = expectationDao.findAllByUid(expectation.getUid());
        expectation1.updata(expectation);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public Expectation query(int uid) {
        return expectationDao.findAllByUid(uid);
    }

}
